package com.lwj.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * @Date 2022/1/29 17:42
 * @Author lwj
 */
@ApiModel(description = "Rest消息")
public class RestEntity<T> {

	@ApiModelProperty(value = "渠道")
	protected String channel;

	@ApiModelProperty(value = "消息主体")
	protected T entity;

	@ApiModelProperty(value = "是否成功")
	protected boolean success = true;

	@ApiModelProperty(value = "异常编码")
	protected String errcode;

	@ApiModelProperty(value = "异常信息")
	protected String errmsg;


	public static RestEntity error(String errmsg){
		return error(errmsg,"500");
	}
	public static RestEntity error(String errmsg,String errcode){
		RestEntity entity=new RestEntity();
		entity.setErrmsg(errmsg);
		entity.setErrcode(errcode);
		entity.setSuccess(false);
		return entity;
	}
	public static<T> RestEntity<T> success(T t){
		RestEntity entity=new RestEntity();
		entity.setEntity(t);
		entity.setErrcode("200");
		entity.setSuccess(false);
		return entity;
	}

	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

	public String getErrmsg() {
		return errmsg;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}

}
